let app = getApp();
import { util } from '../../../utils/util';
import { Base64Img } from '../../../static/base64Img/Base64Img';
var phone=wx.getSystemInfoSync();
Page({
  data:{
    oneArray: [
      {id: 0, name: '思想品德',},{id: 1, name: '学业水平',},{id: 2, name: '身心健康',},{id: 3, name: '艺术素养',},{id: 4, name: '社会实践',},{id: 5, name: '特色项目',},
     ],
    twoArray: [], 
    show_modle : false,
    hide:0,
    oneIndex: 0,
    twoIndex: 0,
    //归档
    archiveCount:0,
    //公式
    publicityCount:0,
    //确认
    confirmCount:0,
    //上报
    totalCount:0,
    info:[],
    sxbk:Base64Img.sxbk,
    y:phone.windowHeight*0.8,
    x:phone.windowWidth,
    windowHeight:phone.windowHeight,

  },
  oneBindObjPickerChange(e) {
    console.log('1picker发送选择改变，携带值为', e.detail.value);
    this.setData({
      oneIndex: e.detail.value,
    });
    if(e.detail.value==0){
       wx.redirectTo({
        url: '/pages/stu-list/detail/index?type=0'   //跳转至思想品德
        })
    }else if(e.detail.value==1){
         wx.redirectTo({
        url: '/pages/stu-list/xysp/xysp?type=1'   //跳转至学业水平
        })
    }
    else if(e.detail.value==2){
         wx.redirectTo({
        url: '/pages/stu-list/sxjk/sxjk?type=2'   //跳转至身心健康
        })
    }
    else if(e.detail.value==3){
         wx.redirectTo({
        url: '/pages/stu-list/yssy/yssy?type=3'   //跳转至艺术素养
        })  
    }
    else if(e.detail.value==4){
         wx.redirectTo({
            url: '/pages/stu-list/shsj/shsj?type=4'   //跳转至社会实践
            })
    }else if(e.detail.value==5){
         wx.redirectTo({
          url: '/pages/stu-list/tsxm/tsxm?type=5'   //跳转至特色项目
          })
    }
  },
  twoBindObjPickerChange(e) {
    
    console.log('2picker发送选择改变，携带值为', e.detail.value);
    this.setData({
      twoIndex: e.detail.value,
    });
    this.getStrdentList();
  },
  clickCknr(){
    this.setData({
       show_modle : true,
    });
  },
   clickCancal(){
    this.setData({
       show_modle : false,
    });
     
  },
  //进入实例详情
   selectInfo(e){
     var me = this;
     //获取的数据格式   类型，实例id
      var str = e.currentTarget.dataset.index+"";
      var arr = str.split(",");
      var type = arr[0];
      var instanceId = arr[1];

    if(type==110||type==111){
          wx.navigateTo({
          url: '/pages/InstanceInfo/sxpd/from-sxdt/InstanceInfo?instanceId='+instanceId   //跳转至党团，社团
        })
      }else if(type==112){
        wx.navigateTo({
          url: '/pages/InstanceInfo/sxpd/from-gyhd/from-gyhd?instanceId='+instanceId   //跳转至公益活动
        })
      }
      else if(type==113){
        wx.navigateTo({
          url: '/pages/InstanceInfo/sxpd/from-zyfw/from-zyfw?instanceId='+instanceId   //跳转至志愿服务
        })
      }
      else if(type==114){
        wx.navigateTo({
          url: '/pages/InstanceInfo/sxpd/from-grry/from-grry?instanceId='+instanceId   //跳转至个人荣誉
        })
      }
      else if(type==115){
        wx.navigateTo({
          url: '/pages/InstanceInfo/sxpd/from-bljl/from-bljl?instanceId='+instanceId   //跳转至不良记录
        })
      }
      else if(type==116){
        wx.navigateTo({
          url: '/pages/InstanceInfo/sxpd/from-other/from-other?instanceId='+instanceId   //跳转至其它
        })
      }
  },

  //获取实例图片
   selectImg(e){
     var me = this;
     //获取的数据格式   类型，实例id
      var str = e.currentTarget.dataset.index+"";
      var arr = str.split(",");
      var type = arr[0];
      var instanceId = arr[1];
      util.selectImg(instanceId)
      .then(function(res) {
        wx.previewImage({
          current: 0,
          urls: res,
       });
    })
  },

  sxpdXssb(){
     wx.navigateTo({
       url: '/pages/create/index?type=0'   //跳转至思想品德
      })
  },
  onLoad(query) {
    var me = this;
    // 页面加载
    this.setData({
      hide: query.type,
      oneIndex: query.type,
      info : [],
    });
    //获取学期列表
    util.getSemesterList().then(
      function(res){
        if(res.data.code==0){
          me.setData({
            twoArray: res.data.info.data||[]
          });

        }else{
           wx.showToast({
                icon: 'fail',
                title: res,
                duration: 3000,
          });
        }

      }
    );

    me.getStrdentList();
  },
  //调用接口获取学生实例列表
  getStrdentList(){
      var me = this;
      var data = {};
      if(me.data.twoArray!=''){
        data =  {
            //传输实例id
            activityType: parseInt(this.data.oneIndex)+1,
            semester: this.data.twoArray[this.data.twoIndex].semester
           }
      }else{
         data =  {
            //传输实例id
            activityType: parseInt(this.data.oneIndex)+1,
           }
      }

     //调用钉钉端接口,获取学生首页list
      this.setData({
        info : [],
      });
     wx.request({
         url: app.ZsServerAddress+'/facts/getStudentList',
         method: 'POST',
         data:data,
         dataType: 'json',
         header: {
            'Content-Type'	: 'application/x-www-form-urlencoded',
            'Authorization' : 'Bearer '+app.token,
         },
          success: function(res) {
            console.log(res)
            if(res.data.code==0){
                if(res.data.info==''){
                  wx.showToast({
                    icon: 'success',
                    title: "暂无查询到该类型数据",
                    duration: 3000,
                  });

                }else{
                  me.setData({
                      archiveCount : res.data.info.archiveCount,
                      publicityCount : res.data.info.publicityCount,
                      confirmCount : res.data.info.confirmCount,
                      totalCount : res.data.info.totalCount,
                      info:res.data.info.data
                  })
                }
            }else{
              wx.showToast({
                icon: 'fail',
                title: res.data.message,
                duration: 3000,
              });
            }
                     
          },
          fail: function(res){     
            util.showError(JSON.stringify(res.errMsg))         
          },
           complete: function(res) { 
          }
     })
     //util.hideLoading()
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
    var me = this;
    me.getStrdentList();
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
});
